package com.springboot.rabbitmq.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.ReturnedMessage;
import org.springframework.amqp.rabbit.core.RabbitTemplate;

/**
 * 消息发送失败返回监听器
 *  ReturnCallback 接口，启动消息失败返回，比如路由不到队列时触发回调
 */
@Slf4j
public class MsgSendReturnCallback implements RabbitTemplate.ReturnsCallback {

    @Override
    public void returnedMessage(ReturnedMessage returned) {
        String msgJson  = new String(returned.getMessage().getBody());

        log.info("ReturnCallback,消息：{}--->回应码：{}--->回应信息：{}--->交换机：{}--->路由键：{}", msgJson
                );
    }
}
